package com.xquant.marketdata.marketdata.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.xquant.common.core.constant.Constants;
import com.xquant.common.redis.service.RedisService;
import com.xquant.marketdata.marketdata.domain.InstrumentPrice;
import com.xquant.marketdata.marketdata.mapper.DailyPriceMapper;
import com.xquant.marketdata.marketdata.service.DailyPriceService;
import com.xquant.xtps.hqprotocol.common.HQItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author B946
 * @date 27/11/2020 14:15
 * @description:
 */
@Service
public class DailyPriceServiceImpl implements DailyPriceService {

    @Autowired
    private DailyPriceMapper dailyPriceMapper;
    @Autowired
    private RedisService redisService;


    private static final Logger logger = LoggerFactory.getLogger(DailyPriceServiceImpl.class);

    @Override
    public InstrumentPrice getMarketPrice(Map<String, Object> param) {

        InstrumentPrice instrumentPrice = null;
        String begDate = String.valueOf(param.get("begDate"));
        String iCode = String.valueOf(param.get("iCode"));
        String aType = String.valueOf(param.get("aType"));
        String mType = String.valueOf(param.get("mType"));

        return instrumentPrice;
    }

    @Override
    public Map<String, Object> getMarketPriceByBegDate(Map<String, Object> param) {
        List<String> list = redisService.getDimCacheObject(Constants.SYS_CONFIG_KEY + "*" + Constants.SYS_TABLE_MARKET_KEY + param.get("aType"));
        if (list.size() == 1) {
            // 获取并设置交易日
            String tradeDate = dailyPriceMapper.getTradeDate(param);
            param.put("begDate",tradeDate);
            param.put("marketTable", redisService.getCacheObject(list.get(0)));
            return dailyPriceMapper.getMarketPriceByBegDate(param);
        } else {
            return null;
        }
    }

}
